package com.lanou.dllo.findfood.adpter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.lanou.dllo.findfood.entity.HomeTopDeals;
import com.lanou.dllo.findfood.fragment.HomeTopFragment;

import java.util.List;

/**
 * Created by dllo on 15/10/21.
 */
public class HomeViewPagerAdpter extends FragmentPagerAdapter {

    private List<HomeTopDeals> dealses;

    public void addData(List<HomeTopDeals> dealse) {
        dealses = dealse;
        notifyDataSetChanged();
    }

    public HomeViewPagerAdpter(FragmentManager fm) {

        super(fm);
    }

    @Override
    public Fragment getItem(int position) {
        HomeTopDeals d = dealses.get(position % dealses.size());
        String image = d.getImage();
        int deal_id = d.getDeal_id();
        String title = d.getTitle();

        String description = d.getDescription();
        return HomeTopFragment.getInstrance(title, image, position, deal_id, description);
    }

    @Override
    public int getCount() {

        return dealses != null && dealses.size() > 0 ? Integer.MAX_VALUE : 0;
    }
}
